#include <bits/stdc++.h>
using namespace std;
int n;
string op, ad;
map <string, int> mp;

bool check_server() {
	if (op[0] != 'S') return false;
	if (op[1] != 'e') return false;
	if (op[2] != 'r') return false;
	if (op[3] != 'v') return false;
	if (op[4] != 'e') return false;
	if (op[5] != 'r') return false;
	return true;
}

bool check_client() {
	if (op[0] != 'C') return false;
	if (op[1] != 'l') return false;
	if (op[2] != 'i') return false;
	if (op[3] != 'e') return false;
	if (op[4] != 'n') return false;
	if (op[5] != 't') return false;
	return true;
}

bool check_ERR() {
	long long a[10];
	int lena[10];
	memset(a, 0, sizeof (a));
	memset(lena, 0, sizeof (lena));
	int tota = 0, totb = 0, tot = 1; //tota -> '.', totb -> ':' 
	int len = ad.length();
	if (ad[0] < '0' || ad[0] > '9') return false;
	for (int i = 0; i < len; ++i) {
		if (tota > 3 || totb > 1) return false;
		if (i == 0) {
			if (ad[i] == '0' && ad[i + 1] != '.') return false;
		}
		if (i != 0 && tot != 5 && ad[i] == '0'){
			if (a[tot] == 0) {
				if (ad[i - 1] != '.' && ad[i - 1] != ':') return false;
				if (i != len - 1)
					if (ad[i + 1] != '.' && ad[i + 1] != ':') return false;
			}
		}
		if ((ad[i - 1] == ':' && i != len - 1 && ad[i] == '0')) return false;
		if ((ad[i] < '0' || ad[i] > '9') && (ad[i] != '.' && ad[i] != ':')) return false;
		if (ad[i] == '.'){
			if (i == len - 1) return false;
			if (ad[i + 1] == '.' || ad[i + 1] == ':') return false;
			++tota, ++tot;
		} 
		if (ad[i] == ':'){
			if (tota != 3) return false;
			if (i == len - 1) return false;
			++totb, ++tot;
		} 
		if (ad[i] >= '0' && ad[i] <= '9') {
			a[tot] = a[tot] * 10 + ad[i] - '0';
			++lena[tot];
			if (tot >= 1 && tot <= 4) if (lena[tot] > 3) return false;
			if (tot == 5) if (lena[tot] > 5) return false;
		}
	}
	if (a[1] < 0 || a[1] > 255) return false;
	if (a[2] < 0 || a[2] > 255) return false;
	if (a[3] < 0 || a[3] > 255) return false;
	if (a[4] < 0 || a[4] > 255) return false;
	if (a[5] < 0 || a[5] > 65535) return false;
	if (tota != 3 || totb != 1) return false;
	return true;
}

int main() {
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> op >> ad;
		if (!check_ERR()) {
			printf("ERR\n");
			continue;
		}
		if (check_server()) {
			if (mp[ad] == 0) {
				mp[ad] = i;
				printf("OK\n");
				
			}
			else printf("FAIL\n");
		}
		if (check_client()) {
			if (mp[ad] == 0) {
				printf("FAIL\n");
			}
			else printf("%d\n", mp[ad]);
		}
	}
	return 0;
}
